<!DOCTYPE html>
<head> 
    <meta charset="utf-8"> 
    <title>连接数据库测试</title>  
</head>
<?php
	$conn = @mysql_connect("localhost","root","sdata007");
	if(!$conn){
		die("连接数据库失败：". mysql_error());
	}else{
		echo "连接数据库成功";
		echo "<br>";
	}
	//if(@mysql_query("CREATE DATABASE testdb", $conn)){
//		echo "创建数据库成功！";	
//	}else{
//		echo "创建数据库失败！" . mysql_error();	
//	}
	//选择数据库
	mysql_select_db("testdb",$conn);
	//创建数据表SQL
	$sql = "CREATE TABLE user(
		uid mediumint(8),
		username varchar(20),
		password char(32),
		email varchar(40),
		regdate int(10)
	)";
	//添加数据表2
	$sql2 = "CREATE TABLE user2(
		uid mediumint(8) unsigned NOT NULL auto_increment,
		username char(15) NOT NULL default '',
		password char(32) NOT NULL default '',
		email varchar(40) NOT NULL default '',
		regdate int(10) unsigned NOT NULL default '0',
		PRIMARY KEY (uid),
		UNIQUE KEY username (username),
		KEY email (email)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
	//增加字段
	$sql3 = "ALTER TABLE user ADD status TINYINT(1) UNSIGNED NULL";
	//删除字段
	$sql4 = "ALTER TABLE user DROP status";
	//改变字段名称和属性
	$sql5 = "ALTER TABLE user CHANGE status_link status INT(15) UNSIGNED NULL DEFAULT '0'";
	//增加索引
	$sql6 = "ALTER TABLE user ADD INDEX(status)";
	//修改索引名及索引属性
	$sql7 = "ALTER TABLE user DROP INDEX status, ADD INDEX email(email)";
	//重命名表
	$sql8 = "RENAME TABLE user2 TO myuser";
	if(!mysql_query($sql8,$conn)){
		echo "操作失败：" . mysql_error();
	}else{
		echo "操作成功！";	
	}
	mysql_close( $conn );
?>